// Mail HTML Script for TurboIRC #debug // Change these parameters #define MYNAME Michael #define MYMAIL xmic@freemail.gr #define PRIORITY 9 if ("$1"!="") goto whandle endif HTML_Load() // Get MailServer string MailServ = GetString("General","MailServer","","C:\\TURBOIRC\\PREF.INI") string V = sprintf("%s;%s",MailServ,"25") // Show HTML HTML_SetArgs(V) HTML_Show("file://C:\\TURBOIRC\\SCRIPTS\\MAIL.HTM") V = HTML_GetArgs() HTML_Free() if (V=="") return endif string _Server = GetParameter(0,V) string _Port = GetParameter(1,V) staticstring _To = GetParameter(2,V) staticstring _Subject = GetParameter(3,V) staticstring _Attach = GetParameter(4,V) staticstring _Message = GetZParameter(5,V) int PP = atoi(_Port) // Now the dirty work staticint sss = socket(1) staticint m_stat = 0 if (connect(sss,_Server,PP)!=0) goto Err endif // Create the window int hPar = GetWOPTIONS($servernumber,"Frame") staticint m_hWnd = CreateWindow(1808,"frame","Mailing...",281735168,50,50,311,250,hPar,0,16744576) // ListBox CreateWindow(0,"listbox","",1350631424,0,0,311,250,m_hWnd,101,0) SetWindowHandler(m_hWnd,33000,-1,-1,"ASM") // FD_READ WSAAsyncSelect(sss,m_hWnd,33000,1) return :whandle string _ToSend = "" int _SendL = 0 if (m_stat==5) goto Stat5 endif if (m_stat==4) m_stat = 5 ; the status will manage it goto Stat4 endif if (m_stat==3) m_stat = 4 goto Stat3 endif if (m_stat==2) m_stat = 3 goto Stat2 endif if (m_stat==1) m_stat = 2 goto Stat1 endif if (m_stat==0) m_stat = 1 goto Stat0 endif // Status 0 :Stat0 // Receive Answer _ToSend = recv(sss,1000,0) if (WSAGetLastError()==10035) return endif if (strncmp(_ToSend,"2",1)!=0) goto Err endif // Send HELO , MAIL , RCPT SendMessage(GetDlgItem(m_hWnd,101),384,-1,"Connected.") _ToSend = "HELO there" _ToSend = AddCRLF(_ToSend) _SendL = strlen(_ToSend) send(sss,_ToSend,_SendL,0) // Status 1 :Stat1 // Receive Answer _ToSend = recv(sss,1000,0) if (WSAGetLastError()==10035) return endif if (strncmp(_ToSend,"2",1)!=0) goto err endif // MAIL FROM SendMessage(GetDlgItem(m_hWnd,101),384,-1,"Sending sender...") _ToSend = "MAIL FROM:" _ToSend = AddCRLF(_ToSend) _SendL = strlen(_ToSend) send(sss,_ToSend,_SendL,0) // Status 2 :Stat2 // Receive Answer _ToSend = recv(sss,1000,0) if (WSAGetLastError()==10035) return endif if (strncmp(_ToSend,"2",1)!=0) goto Err endif // RCPT TO SendMessage(GetDlgItem(m_hWnd,101),384,-1,"Sending receipient...") _ToSend = sprintf("RCPT TO:<%s>",_To) _ToSend = AddCRLF(_ToSend) _SendL = strlen(_ToSend) send(sss,_ToSend,_SendL,0) // Status 3 :Stat3 // Receive Answer _ToSend = recv(sss,1000,0) if (WSAGetLastError()==10035) return endif if (strncmp(_ToSend,"2",1)!=0) goto Err endif // DATA SendMessage(GetDlgItem(m_hWnd,101),384,-1,"Sending data request...") _ToSend = "DATA" _ToSend = AddCRLF(_ToSend) _SendL = strlen(_ToSend) send(sss,_ToSend,_SendL,0) // Status 4 :Stat4 // Receive Answer _ToSend = recv(sss,1000,0) if (WSAGetLastError()==10035) return endif if (strncmp(_ToSend,"354",3)!=0) goto Err endif // Send message heh SendMessage(GetDlgItem(m_hWnd,101),384,-1,"Sending message...") // Format message // Formula // 1 : Header in MAIL_1.hdr // 2 : Subject attach // 3 : Rest Header in MAIL_2.hdr // 4 : Message // 5 : Delimiter in MAIL_3.hdr // 6 : Attachment encoded // 7 : Delimiter in MAIL_3.hdr staticstring _mfile = CreateTemporaryFile() string _CRLF = "" string _QT = """ string _TMP = "" _CRLF = AddCRLF(_CRLF) AppendTextCRLF(_mfile,"Message-ID: <44TurboIRC0005MailScript>") AppendTextCRLF(_mfile,"From: "MYNAME" ") AppendTextCRLF(_mfile,"To: "TurboIRC Mail Script Transfer" ") _TMP = sprintf("Subject : %s\r\n",_Subject) AppendText(_mfile,_TMP) AppendTextCRLF(_mfile,"MIME-Version: 1.0") AppendTextCRLF(_mfile,"X-Priority: PRIORITY") AppendTextCRLF(_mfile,"X-Mailer: TurboIRC 98 IRCX Client by Chourdakis Michael (xmic@freemail.gr) - Mail Script") AppendTextCRLF(_mfile,"Content-Type: multipart/mixed;") AppendTextCRLF(_mfile,"\tboundary=\x22----=_NextPart_000_TurboIRC\x22") AppendTextCRLF(_mfile,"X-MimeOLE: Produced by TurboIRC 98") AppendText(_mfile,_CRLF) AppendText(_mfile,_CRLF) AppendTextCRLF(_mfile,"This is a multi-part message in MIME format.") AppendText(_mfile,_CRLF) AppendText(_mfile,_CRLF) // Message AppendTextCRLF(_mfile,"------=_NextPart_000_TurboIRC") AppendTextCRLF(_mfile,"Content-Type: text/plain;") AppendTextCRLF(_mfile,"\tcharset=\x22iso-8859-7\x22") AppendTextCRLF(_mfile,"Content-Transfer-Encoding: 7bit") AppendText(_mfile,_CRLF) AppendText(_mfile,_CRLF) AppendText(_mfile,_Message) AppendText(_mfile,_CRLF) AppendText(_mfile,_CRLF) AppendText(_mfile,_CRLF) AppendTextCRLF(_mfile,"------=_NextPart_000_TurboIRC") if (_Attach!="*") // attach also string vf = CreateTemporaryFile() string vw = FullToShort(_Attach) FileToBase64(_Attach,vf) //AppendTextCRLF(_mfile,"Content-Type: application/octet-stream;") _TMP = sprintf("Content-Type: application/octet-stream; name=\x22%s\x22\r\n",vw) AppendText(_mfile,_TMP) AppendTextCRLF(_mfile,"Content-Transfer-Encoding: base64") AppendTextCRLF(_mfile,"Content-Disposition: attachment;") _TMP = sprintf("Content-Disposition: attachment; filename=\x22%s\x22\r\n",vw) AppendText(_mfile,_TMP) AppendText(_mfile,_CRLF) AppendText(_mfile,_CRLF) AppendFile(_mfile,vf) AppendText(_mfile,_CRLF) AppendText(_mfile,_CRLF) AppendTextCRLF(_mfile,"------=_NextPart_000_TurboIRC") DeleteFile(vf) endif AppendText(_mfile,_CRLF) AppendText(_mfile,_CRLF) AppendText(_mfile,_CRLF) AppendText(_mfile,".") AppendText(_mfile,_CRLF) // Now _mfile has the mail to be sent ! int fLen = GetFileSize(_mfile); int hFile = CreateFile(_mfile,0,3) if (hFile==-1) goto Err endif SetFilePointer(hFile,0,0); int zz = 0 string ReadHere = "" int SizeSent = 0 for (SizeSent = 0 ; SizeSent < fLen ; ) ReadHere = ReadFile(hFile,100) zz = fLen - SizeSent if (zz > 100) SizeSent += send(sss,ReadHere,100,0) else SizeSent += send(sss,ReadHere,zz,0) break endif // Update File Pointer based to SizeSent SetFilePointer(hFile,SizeSent,0) endfor CloseFile(hFile) // Status 5 :Stat5 // Receive Answer _ToSend = recv(sss,1000,0) if (WSAGetLastError()==10035) return endif if (strncmp(_ToSend,"2",1)!=0) goto Err endif // Terminate closesocket(sss) DestroyWindow(m_hWnd) //DeleteFile(_mfile) /destroystaticvariable m_hWnd /destroystaticvariable sss /destroystaticvariable m_stat /destroystaticvariable _To /destroystaticvariable _Message /destroystaticvariable _Subject /destroystaticvariable _Attach /destroystaticvariable _mfile /addtext ! 4***Mail sent successfully !! return :Err closesocket(sss) DestroyWindow(m_hWnd) //DeleteFile(_mfile) /destroystaticvariable m_hWnd /destroystaticvariable sss /destroystaticvariable _To /destroystaticvariable _Message /destroystaticvariable _Subject /destroystaticvariable _Attach /destroystaticvariable m_stat /destroystaticvariable _mfile /addtext ! SendMail failed !